<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2018/12/13
  Time: 20:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <jsp:include page="${pageContext.request.contextPath}/common/tag.jsp"/>
    <script>
        $(function () {
           $("#tu").click(function () {
             $("[name='multipartFile']").click();
           });
            $("[name='multipartFile']").change(function(){
                $("#tu").attr("src",URL.createObjectURL($(this)[0].files[0]));
            });

            $("#addimg").click(function () {
                var multipartFile = $("[name='multipartFile']").val();
                var form = new FormData();
                form.append("goodsMain",multipartFile);


                /*$.post("",{"multipartFile":obj},function (data) {
                   alert("123456");
                });*/

                $.ajax({
                    type : 'post',
                    data:new FormData($("#uploadForm")[0]),
                    url : '${pageContext.request.contextPath}/shangchuan/tupian',
                    contentType: false, //必须false才会自动加上正确的Content-Type
                    processData: false,//必须false才会避开jQuery对 formdata 的默认处理XMLHttpRequest会对 formdata 进行正确的处理
                    success : function (data) {
                        $.post("",{},function () {
                            
                        })
                    }
                })
            });
        });
    </script>
</head>
<body>
<form action=""  method="post" id="uploadForm" enctype="multipart/form-data">
    <div>
        <img id="tu" src="${pageContext.request.contextPath}/xitong/img/touxiang1.jpg" width="100px;" height="100px;">
    </div>
    <input type="file" name="multipartFile" style="display: none;"/><br/>
    <input type="button" id="addimg" value="添加">
</form>
</body>
</html>
